package com.sheng.center.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.sheng.center.entity.Repair;

public class RepairDaoImpl implements RepairDao {

	private SessionFactory sessionFactory;
	@Override
	public void add(Repair repair) {
		repair.setIsDelete(0);
			sessionFactory.getCurrentSession().save(repair);
	}

	@Override
	public void edit(Repair repair) {
		repair.setIsDelete(0);
			sessionFactory.getCurrentSession().update(repair);
	}

	@Override
	public void delete(Repair repair) {
		repair.setIsDelete(1);
		sessionFactory.getCurrentSession().update(repair);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Repair> findAllList(Repair model) {
		String hql = "from Repair where 1=1  and is_delete=0";
		if(null != model.getDeviceName()){
			hql = hql + " and device_name like '%"+model.getDeviceName()+"%'";
		}
		Query query = sessionFactory.getCurrentSession().createQuery(hql);  
        List list = query.list();  
        return list;
	}
	public Repair findById(Repair repair) {
		Query query = sessionFactory.getCurrentSession().createQuery("from Repair where id='"+repair.getId()+"'");  
		List list = query.list();  
		if (null != list && 0 < list.size()) {
			repair = (Repair) list.get(0);
		}
		return repair;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
